package com.example.helloImageDetection;

import gestoreImmagini.ListaLoghiCursorAdapter;
import gestoreImmagini.MyDbConnector;
import android.app.ListActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListAdapter;

public class MostraLoghiActivity extends ListActivity{

	ListAdapter mAdapter;
	MyDbConnector dbConn;
	
	Button mTornaMain;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mostra_loghi); 
		
		mTornaMain = (Button)findViewById(R.id.mostra_loghi_ok);
		mTornaMain.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				finish();
			}
		});
		
		dbConn = MyDbConnector.getDbConnector(this);
		
		/*recupero il cursore per mostrare i loghi*/
		SQLiteDatabase db = dbConn.getReadableDatabase();
		Cursor cursor = db.query(false, "loghi", new String[]{"_id", "nome", "descrizione", "logo"}, null, null, null, null, null, null);
		startManagingCursor(cursor);
				
		String[] columns = new String[] {"nome", "descrizione", "logo"};
		int[] to = new int[] {R.id.riga_logo_nome, R.id.riga_logo_descrizione, R.id.riga_logo_logo};
		
		mAdapter = new ListaLoghiCursorAdapter(this, R.layout.riga_logo, cursor, columns, to);
		
		setListAdapter(mAdapter);
		
	}
	
	

}
